<template>
	<scroll-view scroll-y class="viewport">
		<!-- 基本信息 -->
		<view class="goods">
			<!-- 商品主图 -->
			<view class="preview">
				<swiper circular autoplay="true">
					<swiper-item>
						<image mode="aspectFill" :src="imgSrc+goods.picture"></image>
					</swiper-item>
				</swiper>
				<view class="indicator">
					<text class="current">1</text>
					<text class="split">/</text>
					<text class="total">1</text>
				</view>
			</view>

			<!-- 商品简介 -->
			<view class="meta">
				<view class="price">
					<text class="symbol">¥</text>
					<text class="number">{{goods.price}}</text>
				</view>
				<view class="name ellipsis">{{goods.theme}} </view>
			</view>
		</view>

		<!-- 商品详情 -->
		<view class="detail panel">
			<view class="title">
				<text>详情</text>
			</view>
			<view class="content">
				<view class="properties">
					<!-- 属性详情 -->
					<view class="item">
						<text class="label">{{goods.goodsDescribe}}</text>
					</view>
				</view>
			</view>
		</view>
	</scroll-view>

	<!-- 用户操作 -->
	<view class="toolbar">
		<view class="icons">
			<image src="../../static/images/price.png" mode=""></image>
			<text>商品</text>
		</view>
		<view class="buttons">
			<view class="buynow" @click="showInputDialog"> 立即购买 </view>
		</view>
	</view>
</template>
<script>
	import homeGoods from "@/api/homeGoods.js"
	export default {
		data() {
			return {
				//商品信息
				goods: [],
				param:{
					//交易地址
					buyerAddress:'',
					//商品id
					goodsId:''
				},
				//图片地址
				imgSrc:"https://xxgc-lin-blog.oss-cn-chengdu.aliyuncs.com/",
			}
		},
		onLoad: function(option) {
			// console.log(option.id)
			//接收商品id，通过id查询商品信息
			this.getGoods(option.id)
			this.param.goodsId = option.id
		},
		methods: {
			//通过id查询商品信息
			getGoods(goodsId) {
				homeGoods.goodsById(goodsId).then(data => {
					console.log(data)
					this.goods = data.data
				})
			},
			showInputDialog() {
			      uni.showModal({
			        title: '请输入收货地址',
			        content: '',
			        editable:true,//是否显示输入框
					placeholderText:'请输入正确交易地址号',//输入框提示内容
			        confirmText: '确认',
			        cancelText: '取消',
			        success: (res) => {
			          if (res.content!='' && res.content!= null) {
			            console.log('输入的内容：', res.content);
						this.param.buyerAddress = res.content
						console.log(this.param)
						homeGoods.buyGoods(this.param).then(res=>{
							console.log(res)
							uni.navigateBack()
						})
			          }
			        } 
			      });
			    }
		}
	}
</script>
<style lang="scss">
	page {
		height: 100%;
		overflow: hidden;
		display: flex;
		flex-direction: column;
	}

	.viewport {
		background-color: #f4f4f4;
	}

	.panel {
		margin-top: 20rpx;
		background-color: #fff;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 90rpx;
			line-height: 1;
			padding: 30rpx 60rpx 30rpx 6rpx;
			position: relative;

			text {
				padding-left: 10rpx;
				font-size: 28rpx;
				color: #333;
				font-weight: 600;
				border-left: 4rpx solid #27ba9b;
			}

			navigator {
				font-size: 24rpx;
				color: #666;
			}
		}
	}

	.arrow {
		&::after {
			position: absolute;
			top: 50%;
			right: 30rpx;
			content: '\e6c2';
			color: #ccc;
			font-family: 'erabbit' !important;
			font-size: 32rpx;
			transform: translateY(-50%);
		}
	}

	/* 商品信息 */
	.goods {
		background-color: #fff;

		.preview {
			height: 550rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}

			swiper {
				width: 100%;
				height: 100%;
			}

			.indicator {
				height: 40rpx;
				padding: 0 24rpx;
				line-height: 40rpx;
				border-radius: 30rpx;
				color: #fff;
				font-family: Arial, Helvetica, sans-serif;
				background-color: rgba(0, 0, 0, 0.3);
				position: absolute;
				bottom: 30rpx;
				right: 30rpx;

				.current {
					font-size: 26rpx;
				}

				.split {
					font-size: 24rpx;
					margin: 0 1rpx 0 2rpx;
				}

				.total {
					font-size: 24rpx;
				}
			}
		}

		.meta {
			position: relative;
			border-bottom: 1rpx solid #eaeaea;

			.price {
				height: 130rpx;
				padding: 25rpx 30rpx 0;
				color: #fff;
				font-size: 34rpx;
				box-sizing: border-box;
				background-color: #35c8a9;
			}

			.number {
				font-size: 56rpx;
			}

			.brand {
				width: 160rpx;
				height: 80rpx;
				overflow: hidden;
				position: absolute;
				top: 26rpx;
				right: 30rpx;
			}

			.name {
				max-height: 88rpx;
				line-height: 1.4;
				margin: 20rpx;
				font-size: 32rpx;
				color: #333;
			}

			.desc {
				line-height: 1;
				padding: 0 20rpx 30rpx;
				font-size: 24rpx;
				color: #cf4444;
			}
		}

		.action {
			padding-left: 20rpx;

			.item {
				height: 90rpx;
				padding-right: 60rpx;
				border-bottom: 1rpx solid #eaeaea;
				font-size: 26rpx;
				color: #333;
				position: relative;
				display: flex;
				align-items: center;

				&:last-child {
					border-bottom: 0 none;
				}
			}

			// .label {
			// // 	width: 100%;
			// // 	color: #898b94;
			// // 	margin: 0 16rpx 0 10rpx;
			// // }

			.text {
				flex: 1;
				-webkit-line-clamp: 1;
			}
		}
	}

	/* 商品详情 */
	.detail {
		padding-left: 20rpx;

		.content {
			margin-left: -20rpx;
		}

		.properties {
			padding: 0 20rpx;
			margin-bottom: 30rpx;

			.item {
				display: flex;
				line-height: 2;
				padding: 10rpx;
				font-size: 26rpx;
				color: #333;
				border-bottom: 1rpx dashed #ccc;
			}

			.label {
				width: 100%;
				padding: 15rpx;
			}

			.value {
				flex: 1;
			}
		}
	}



	/* 底部工具栏 */
	.toolbar {
		width: 100%;
		position: fixed;
		bottom: 0;

		background-color: #fff;
		height: 150rpx;
		border-top: 1rpx solid #eaeaea;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: content-box;

		.buttons {
			display: flex;

			&>view {
				width: 220rpx;
				text-align: center;
				line-height: 72rpx;
				font-size: 26rpx;
				color: #fff;
				border-radius: 72rpx;
			}

			.addcart {
				background-color: #ffa868;
			}

			.buynow {
				background-color: #27ba9b;
				margin-left: 20rpx;
				margin-right: 2%;
			}
		}

		.icons {
			margin-left: 2%;
			padding-right: 10rpx;
			display: flex;
			align-items: center;
			flex: 1;

			image {
				width: 50rpx;
				height: 50rpx;
			}

			text {

				position: absolute;
				font-size: 24rpx;
				margin-top: 70rpx;
				color: #333;
			}

		}
	}
</style>